package com.example.rule.common.enums;

import com.example.rule.common.exception.ClientException;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum ConditionLogicEnum {
    ALL_MATCH("全都满足", "&&"),
    ANY_MATCH("任意满足", "||"),
    NONE_MATCH("都不满足", "&&");

    private final String description;
    private final String operator;

    ConditionLogicEnum(String description, String operator) {
        this.description = description;
        this.operator = operator;
    }

    private static final Map<String, String> LOGIC_MAP = new HashMap<>();

    static {
        for (ConditionLogicEnum value : values()) {
            LOGIC_MAP.put(value.getDescription(), value.getOperator());
        }
    }

    /**
     * 根据描述获取对应的逻辑操作符
     */
    public static String getOperatorByDescription(String description) {
        String operator = LOGIC_MAP.get(description);
        if (operator == null) {
            throw new ClientException("不支持的逻辑操作符: " + description);
        }
        return operator;
    }
}
